<template>
  <section id="pending">
    <div class="table">
      <table>
        <thead>
          <tr>
            <th>时间</th>
            <th>产品</th>
            <th>手数 (方向)</th>
            <th>开仓价格</th>
            <th>平仓价格</th>
            <th>利息</th>
            <th >平仓时间</th>
            <th >订单号</th>
            <th>盈亏</th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="(item,index) in ddDataList.data" :key="index">
            <td>{{$js.timeToDate(item.time)}}</td>
            <td>{{item.goods_name}}</td>
            <td>{{item.num}}手 / {{item.buy_type==1?'买入':'卖出'}}</td>
            <td>{{item.price}}</td>
            <td>{{item.end_price}}</td>
            <td  >{{item.interest}}</td>
            <td >{{$js.timeToDate(item.create_time)}}</td>
            <td >{{item.order_id}}</td>
            <td  :class="item.yingkui>=0?'red':'green'">{{(item.yingkui>=0?'+':'')+item.yingkui}}</td>
          </tr>
        </tbody>
      </table>
       <Page :total="ddDataList.pages*10" @on-change="pageChange" v-if="ddDataList" class-name="pageUserStyle" />
       <base-nodata v-if="nodataListBol"></base-nodata>
    </div>
     
  </section>
</template>
<script>
import {_getjyOrder} from "../../axios/index.js";
export default {
  data() {
    return {
     page:1,
     ddDataList:"",
     nodataListBol:false
    }
  },
  watch:{
    resetBol(){
      this.page=1;
      this.getMethod();
    },
    countDdDataList(){
      if(this.page==1){
        this.ddDataList=this.countDdDataList;
      }
    }
  },
  computed:{
    countDdDataList(){
      return this.$store.state.ddDataList;
    }
  },
  methods:{
     pageChange(value){
       this.page=value;
       this.getMethod();
     },
    //获取订单记录
    async getMethod() {
      var self = this;
      var data= JSON.parse(JSON.stringify(self.searchData));
      data.uid=self.user.id;
      data.page= self.page;
      const res = await _getjyOrder(data);
      if (res.data.code == 200) {
        var data = res.data.data;
        
        if(self.page==1){
          self.$store.commit("setDdDataList",data);
        }else{
          self.ddDataList=data;
        }
        if (data.data.length) {
          self.nodataListBol=false;
        } else {
          self.nodataListBol=true;
        }
      }
    },
  },
  created() {
    this.getMethod();
  },
  props:["user","resetBol","searchData"]
}
</script>
